package hot100;

import java.util.HashSet;
import java.util.Set;

public class longestConsecutive3 {
    public int longestConsecutive(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for(int x : nums) {
            set.add(x);
        }
        int max = 0;
        for(int x : set) {
            int cur = x;
            int len = 1;
            if(!set.contains(x - 1)) {//找到某个子序列的起始位
                while(set.contains(cur + 1)) {//追踪子序列
                    cur += 1;
                    len++;
                }
            }
            if(max < len) {
                max  = len;
            }

        }

        return max;
    }
}
